import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import "./plugins/element.js";
// 加载Element 组件库
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
// 加载全局样式文件
import "./styles/index.less";

Vue.use(ElementUI);

Vue.config.productionTip = false;

// 全局注册自定义权限校验指令
Vue.directive('permission', {
  bind: function (el, binding) {
      // 获取页面按钮权限
      console.log(binding.value,el.parentNode)
      let btnPermissionsArr = btnPermissionsArr = Array.of(binding.value)
      if (!Vue.prototype.$_has(btnPermissionsArr)) {
        el.parentNode.removeChild(el)
      }
  }
})
// 权限检查方法
Vue.prototype.$_has = function (value) {
  let isExist = false;
  // 获取用户按钮权限
  const user = JSON.parse(window.localStorage.getItem("user"))
  let btnPermissionsStr = user.role
  if (btnPermissionsStr == undefined || btnPermissionsStr == null) {
      return false;
  }
  if (value.indexOf(btnPermissionsStr) > -1) {
      isExist = true;
  }
  return isExist;
};

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");

// 全局注册 element 组件库
Vue.use(ElementUI);

